package task

import (
	"data-center/api/http/handlers/task/task_model"
	"data-center/pkg/queue"
	"data-center/pkg/response"
	"github.com/gin-gonic/gin"
	"go.mongodb.org/mongo-driver/mongo"
	"gorm.io/gorm"
	"net/http"
)

// Handler 任务处理器
type Handler struct {
	// 注入服务依赖
	db       *gorm.DB
	mongo    *mongo.Collection
	producer queue.Producer
}

// NewHandler 创建任务处理器
func NewHandler(db *gorm.DB, mongoClient *mongo.Collection, producer queue.Producer) *Handler {
	return &Handler{
		db:       db,
		mongo:    mongoClient,
		producer: producer,
	}
}

// RegisterRoutes 注册路由
func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
	tasks := r.Group("/tasks")
	{
		tasks.POST("/", h.Create)
		tasks.GET("/:id", h.Get)
		tasks.GET("/", h.List)
		tasks.DELETE("/:id", h.Cancel)
	}
}

// Create 创建任务
func (h *Handler) Create(c *gin.Context) {
	var req task_model.ReqTaskCreate
	if err := c.ShouldBindJSON(&req); err != nil {
		response.Fail(c, http.StatusBadRequest, err.Error())
		return
	}
	
	response.Success(c, "ok")
}

// Get 获取任务详情
func (h *Handler) Get(c *gin.Context) {
	id := c.Param("id")
	response.Success(c, id)
}

// List 获取任务列表
func (h *Handler) List(c *gin.Context) {
	response.Success(c, "ok")
}

// Cancel 取消任务
func (h *Handler) Cancel(c *gin.Context) {
	id := c.Param("id")
	response.Success(c, id)
}
